/*
 * Copyright (c) 2009, Jan Pastor. All Rights Reserved.
 */

package sk.jp.commons.objcache;

/**
 * Cache item.
 *
 * @author Jan Pastor 
 */
class CacheItem<T> {

    private final String id;
    private final T value;
    private final long expTime;

    //------------------------------------------------------------------

    /**
     * Create item instance.
     * @param id unique item ID.
     * @param value item value.
     * @param expTime expiration time.
     */
    CacheItem(String id, T value, long expTime) {
        this.id = id;
        this.value = value;
        this.expTime = expTime;
    }

    //------------------------------------------------------------------

    public String getId() {
        return id;
    }

    public T getValue() {
        return value;
    }

    /**
     * Returns expiration timeout.
     * @return expiration timeout.
     */
    public long getExpTime() {
        return expTime;
    }

    /**
     * Returns true if cache item is expired.
     * @return true if cache item is expired.
     */
    public boolean isExpired(){
        return expTime <= System.currentTimeMillis();
    }

    //------------------------------------------------------------------

    /**
     * Returns a string representation of this instance.
     * @return string representation of this instance.
     */
    public String toString() {
        return "CacheItem{" +
               "id='" + id + '\'' +
               ", value=" + value +
               ", expTime=" + expTime +
               '}';
    }

}
